package org.bee.config;

import org.bee.apis.AdminApis;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.support.RestClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;

@Configuration
public class WebClientConfig {

    /**
     * admin服务地址
     */
    @Value("${rpc.service.admin.url}")
    private String adminServiceUrl;

    /**
     * 内部调用token
     */
    @Value("${rpc.internalToken}")
    private String internalToken;

    @Bean
    public AdminApis adminApis() {
        RestClient restClient = RestClient.builder()
                .baseUrl(adminServiceUrl)
                .defaultHeader("Bee-Internal-Auth", internalToken)
                .build();
        HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder()
                .exchangeAdapter(RestClientAdapter.create(restClient))
                .build();
        return factory.createClient(AdminApis.class);
    }
}
